package ar.edu.caece.pl.asem.model.impl.treeelements;

public class Procedimiento extends MetodoGenerico {

	public Procedimiento(String name) {
		super(name);
		this.setReturnType(-1);
		this.label = "PROCEDIMIENTO";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Procedimiento))
			return false;
		Procedimiento other = (Procedimiento) obj;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getLabel() + ": " + this.getName() + "()";
	}

	@Override
	public void generateASMCode() {
		StringBuffer sb = new StringBuffer();
		String procedureName = this.getName();
		sb.append(procedureName + " proc near \n");
		this.code = sb.toString();
		// Contiene parametros
		if (this.getChildren().get(0).getChildren().size() > 0) {
			for (AbstractElement parameter : this.getChildren().get(0)
					.getChildren()) {
				if (!(parameter.parent instanceof Parametros)) {
					parameter.parent = this;
				}else{
					if(parameter.getEnvName()!=this.getName()){
						parameter.setEnvName(this.getName());
					}
				}
			}
		}
		super.generateASMCode();
	}

}
